define(function(require){
    var main =require('/static/main.js');
    var m = new main();
    function Cont(){
        this.Fun._init();
    }
    Cont.prototype.Fun = {
        Blance:0,
        _init:function(){
            this.getlist();
            this.bindEvent();
        },
        bindEvent:function(){
            var _this = this;
            //提现申请
            $(document).on('click','.CashBtn',function(){
               var Blance = _this.Blance;
                if(Blance < 100){
                    layer.msg("可提现金额小于最小提现金额，不能提现");
                    return false;
                }else{
                    $("#Withdraw").modal('show');
                }
            });

            $(".WithdrawAmount").keyup(function () {
                var reg = $(this).val().match(/\d+\.?\d{0,2}/);
                var txt = '';
                if (reg != null) {
                    txt = reg[0];
                }
                $(this).val(txt);
            }).change(function () {
                $(this).keypress();
                var v = $(this).val();
                if (/\.$/.test(v))
                {
                    $(this).val(v.substr(0, v.length - 1));
                }
            });

            $(".add").click(function(){
                var JsonData = {
                    WithdrawAmount:$("#Withdraw .WithdrawAmount").val().trim()
                }
                if(JsonData.WithdrawAmount.length < 1){
                    layer.msg("请输入提现金额");
                    return false;
                }
                if(Math.floor(JsonData.WithdrawAmount) < 100){
                    layer.msg("提现金额小于最低提现金额");
                    return false;
                }
                if(Math.floor(JsonData.WithdrawAmount) >_this.Blance){
                    layer.msg("提现金额大于可提现金额");
                    return false;
                }
                $.ajax({
                    type: "POST",
                    data: JsonData,
                    url: "/finance/withdraw-apply",
                    dataType: "json",
                    success: function (ret) {
                        if (ret.IsBizSuccess) {
                            layer.msg("提现申请提交成功！");
                            $("#Withdraw").modal('hide');
                            $("#Withdraw .WithdrawAmount").val('');
                            var table1 = $('#datatable').DataTable();
                            table1.ajax.reload();
                        } else {
                            layer.msg(ret.ErrMsg);
                        }
                        layer.close();
                    }
                })
            });


        },
        getlist:function(){
            var _this = this;
            var param = {};
            var sort = 0;
            var table = $('#datatable').dataTable({
                'ordering':false,
                "serverSide": true,
                "searching":false,
                'bLengthChange': false,
                'bPaginate': true,
                "bDestory": true,
                "bRetrieve": true,
                "bFilter":false,
                "bSort": false,
                "bProcessing": true,
                "autoWidth": false,
                ajax: function (data, callback, settings) {
                    //封装请求参数
                    param.PageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                    param.start = data.start;//开始的记录序号
                    param.PageNo = (data.start / data.length)+1;//当前页码
                    sort = (param.PageNo-1)*param.PageSize;
                    //ajax请求数据
                    $.ajax({
                        type: "POST",
                        url: "/finance/get-withdraw-apply-list",
                        cache: false,  //禁用缓存
                        data: param,  //传入组装的参数
                        dataType: "json",
                        success: function (result) {
                            var returnData = {};
                            returnData.draw = data.draw;
                            returnData.recordsTotal = result.total;
                            returnData.recordsFiltered = result.total;
                            returnData.data = result.data;
                            _this.Blance = result.Blance;
                            $(".Count").html(Math.floor(_this.Blance ));
                            callback(returnData);
                        }
                    });
                },
                "aoColumns":[
                    {"mDataProp": 'WithdrawAmount'},
                    {"mDataProp": 'WithdrawMethod',
                        render:function(data){
                            var WithdrawMethod = '';
                            switch(data){
                                case 100:WithdrawMethod = '微信'; break;
                                case 200:WithdrawMethod = '支付宝'; break;
                                case 300:WithdrawMethod = '银行卡'; break;
                            }
                            return WithdrawMethod;
                        }
                    },
                    {"mDataProp": 'BankId'},
                    {"mDataProp": 'WithdrawStatus',
                        render:function(data){
                            var WithdrawStatus = '';
                            switch(data){
                                case 100:WithdrawStatus = '审核中'; break;
                                case 200:WithdrawStatus = '审核通过'; break;
                                case 300:WithdrawStatus = '审核驳回'; break;
                                case 400:WithdrawStatus = '提现成功'; break;
                                case 500:WithdrawStatus = '打款失败'; break;
                            }
                            return WithdrawStatus;
                        }
                    },
                    {"mDataProp": 'AuditTime',
                        render:function(data){
                            if(data){
                                return m.formatTimeAll2(data);
                            }else{
                                return '-';
                            }

                        }
                    },
                    {"mDataProp": 'PayTime',
                        render:function(data){
                            if(data){
                                return m.formatTimeAll2(data);
                            }else{
                                return '-';
                            }

                        }
                    },
                    { "mDataProp": "PayNo"},
                    { "mDataProp": "SerialNo"},
                    {"mDataProp": 'CreateTime',
                        render:function(data){
                            if(data){
                                return m.formatTimeAll2(data);
                            }else{
                                return '-';
                            }

                        }
                    },
                ]
            }).api();

            // 点击搜索
            $('#btnSearch').click(function(){
                param.ENTCode = $('.ENTCode').val();
                param.ENTName = $('.ENTName').val();
                var table = $('#datatable').DataTable();
                table.ajax.reload();

            });
            // 点击重置按钮
            $('#btnRefresh').click(function(){
                $('.ENTCode').val('');
                $('.ENTName').val('');
                param.ENTCode = '';
                param.ENTName = '';
                var table = $('#datatable').DataTable();
                table.ajax.reload();
            });

        }
    }
    var a = new Cont();

})